import neon.guid
import neon.version
import neon.atom
import util.json

t = neon.atom.AtomType('testatom')
t.add_table('tab1')
t.add_table('tab2', ('SELECT guid FROM tab2 WHERE b = ?', ['b']))

a = neon.atom.Atom(t)
a.fields = {'tab1' : [{'guid' : 'test1:1', 'a' : 'YYY'}],
            'tab2' : [{'guid' : 'test1:1', 'b' : 'ZZZ'}]}

assert a.get_guid() == neon.guid.UNSET
assert a.get_version() == neon.version.Vector()
raw = a.to_raw()

b = neon.atom.Atom(t)
b.from_raw(raw)
assert a.to_raw() == b.to_raw()

assert t.intersect_query(a) == [('SELECT guid FROM tab2 WHERE b = ?', ['ZZZ'])]
assert t.intersect_query(a) == t.intersect_query(b)
